package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.web.controller.tool.JsonResult;
import com.ruoyi.web.controller.tool.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JingfeiTuikuanjilu;
import com.ruoyi.system.service.IJingfeiTuikuanjiluService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@Controller
@RequestMapping("/system/tuikuanjilu")
public class JingfeiTuikuanjiluController extends BaseController
{
    private String prefix = "system/tuikuanjilu";

    @Autowired
    private IJingfeiTuikuanjiluService jingfeiTuikuanjiluService;

    @RequiresPermissions("system:tuikuanjilu:view")
    @GetMapping()
    public String tuikuanjilu()
    {
        return prefix + "/tuikuanjilu";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:tuikuanjilu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JingfeiTuikuanjilu jingfeiTuikuanjilu)
    {
        startPage();
        List<JingfeiTuikuanjilu> list = jingfeiTuikuanjiluService.selectJingfeiTuikuanjiluList(jingfeiTuikuanjilu);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:tuikuanjilu:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JingfeiTuikuanjilu jingfeiTuikuanjilu)
    {
        List<JingfeiTuikuanjilu> list = jingfeiTuikuanjiluService.selectJingfeiTuikuanjiluList(jingfeiTuikuanjilu);
        ExcelUtil<JingfeiTuikuanjilu> util = new ExcelUtil<JingfeiTuikuanjilu>(JingfeiTuikuanjilu.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:tuikuanjilu:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JingfeiTuikuanjilu jingfeiTuikuanjilu)
    {
        return toAjax(jingfeiTuikuanjiluService.insertJingfeiTuikuanjilu(jingfeiTuikuanjilu));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:tuikuanjilu:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JingfeiTuikuanjilu jingfeiTuikuanjilu = jingfeiTuikuanjiluService.selectJingfeiTuikuanjiluById(id);
        mmap.put("jingfeiTuikuanjilu", jingfeiTuikuanjilu);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:tuikuanjilu:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JingfeiTuikuanjilu jingfeiTuikuanjilu)
    {
        return toAjax(jingfeiTuikuanjiluService.updateJingfeiTuikuanjilu(jingfeiTuikuanjilu));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:tuikuanjilu:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jingfeiTuikuanjiluService.deleteJingfeiTuikuanjiluByIds(ids));
    }

    /**
     * 余额 退款列表
     */
    @PostMapping("/tuikuanlist")
    @ResponseBody
    public JsonResult<?> tuikuanlist(@RequestParam("deptid")String ppDeptId,
                                     @RequestParam("pageindex") int ppPageIndex,
                                     @RequestParam("pagesize") int ppPageSize)
    {
        try{
            List<JingfeiTuikuanjilu> list = jingfeiTuikuanjiluService.selectTuikuanList(ppDeptId,ppPageIndex, ppPageSize);
            int mmCount = 0;
            mmCount = jingfeiTuikuanjiluService.countTuikuanList(ppDeptId);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);
            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("tuikuanlist", list);
            mmMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmMap);
        } catch (Exception e){
            return JsonResult.getErrorResult("查询退款列表失败");
        }
    }


    /**
     * 余额 收款列表
     */
    @PostMapping("/shoukuanlist")
    @ResponseBody
    public JsonResult<?> shoukuanlist(@RequestParam("deptid")String ppDeptId,
                                      @RequestParam("deptname")String deptName,
                                      @RequestParam("tktime1")String tktime1,
                                      @RequestParam("tktime2")String tktime2,
                                      @RequestParam("status")int status,
                                      @RequestParam("pageindex") int ppPageIndex,
                                     @RequestParam("pagesize") int ppPageSize)
    {
        try{
            List<JingfeiTuikuanjilu> list = jingfeiTuikuanjiluService.selectShoukuanList(ppDeptId,deptName, status, tktime1, tktime2,ppPageIndex, ppPageSize);
            int mmCount = 0;
            mmCount = jingfeiTuikuanjiluService.countShoukuanList(ppDeptId,deptName, status, tktime1, tktime2);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);
            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("shoukuanlist", list);
            mmMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmMap);
        } catch (Exception e){
            return JsonResult.getErrorResult("查询收款列表失败");
        }
    }

}
